<?php
/**
 * 产品类
 * @author chenlisong E-mail:chenlisong1021@163.com 
 * @version 创建时间：2016年10月24日 上午11:58:32 
 * 类说明
 */
class ShopAction extends BaseAction{
	
	public function index(){
		echo $this->err("非法操作！");
	}
	
	/**
	 * 获取此区域的超市
	 */
	public function getAllShop(){
		$shopModel = M("Shop");
		$param = $this->param;
		$where['school_area_id'] = $param['school_area_id'];
		$where['flag'] = 1;
		$field = "id,user_id,name,school_name,floor_num,status,logo,is_super";
		$shopData = $shopModel->where($where)->field($field)->select();
		echo $this->suc($shopData, 0);
	}

	public function test(){
		echo "111111111111111";
		$this->insertNotice(12752,"您有未处理的订单！","1017082113170856");
	}

	/**
	 * 更改状态
	 */
	public function updateStatus() {
		//删除指定记录
		$Model = M($this->getActionName());
		$param = $this->param;
		$user_id = $_REQUEST['userId'];
		if (isset($user_id)) {
			$condition = array("user_id" => $param['userId']);
			$result =  $Model->where($condition)->setField(array("status"=>$param['status']));
			if($result !== false){
				echo $this->suc();
			}else{
				echo $this->err('修改失败！');
			}
		}
	}
	/**
	 * 新增消息
	 * 新增商家待处理订单消息
	 */
	private function insertNotice($userId,$message,$ambulance){
		$Notice = M('Notice');$User = M('User');
		$jpushId = $User->where('id = '.$userId)->getField('jpush_id');
		if(!empty($jpushId)){
			$data['type'] = 1;
			$data['user_id'] = $userId;
			$data['message'] = $message;
			$data['ambulance'] = $ambulance;
			$data['create_time'] = time();
			$Notice->add($data);
		}
		return true;
	}
}